<template>
  <div class='container'>
    <el-dialog
      title="题目审核"
      :visible="ckDialogVisible"
      width="30%"
      @close="closeCkDialog"
      >
      <el-form ref="ckRef" :model="ckForm">
        <el-form-item size="small">
          <el-radio-group v-model="ckForm.chkState">
            <el-radio label="通过"></el-radio>
            <el-radio label="拒绝"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item size="small">
          <el-input type="textarea" v-model="ckForm.chkRemarks" placeholder="请输入审核意见"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('close-ck-dialog')">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck as updateChecked } from '@/api/hmmm/questions'
export default {
  data () {
    return {
      ckForm: {
        chkState: '通过',
        chkRemarks: ''
      }
    }
  },
  props: {
    ckDialogVisible: {
      type: Boolean,
      required: true
    },
    chkID: {
      type: Number,
      required: true
    },
    chkState: {
      type: Object,
      required: true
    }
  },
  methods: {
    closeCkDialog () {
      this.ckForm = {
        chkState: '通过',
        chkRemarks: ''
      }
      this.$emit('close-ck-dialog')
    },
    submit () {
      this.$refs.ckRef.validate(async valid => {
        if (!valid) return
        if (!this.ckForm.chkRemarks) {
          this.$message({
            message: '请输入审核意见',
            type: 'warning'
          })
        } else {
          for (const k in this.chkState) {
            if (this.ckForm.chkState === this.chkState[k]) {
              this.ckForm.chkState = k
            }
          }
          await updateChecked({
            id: this.chkID,
            chkState: +this.ckForm.chkState,
            chkRemarks: this.ckForm.chkRemarks
          })
          // console.log(res)
          this.$message.success('操作成功')
          this.closeCkDialog()
          this.$emit('fetch-questions-list')
        }
      })
    }
  }
}
</script>

<style scoped lang='less'></style>
